<?php

namespace app\batch;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Debug;
use app\models\{Goods, GoodsSpec, SystemGoods, SystemGoodsSpec,OrderGoods,Banner};
use think\Db;
use think\facade\Log;
use think\facade\Env;
use app\facade\Redis;

class Rebot extends Command
{
    protected $open = false;
    protected function configure()
    {
        $this->setName('Rebot')->setDescription('测试');
    }

    protected function execute(Input $input, Output $output)
    {
        $this->doCron();
        die();
    }

    protected function doCron()
    {
        ini_set('max_execution_time', 0);
        $goods = (new Goods())->select();
        foreach($goods as $good){
            $good['images'] = json_decode($good['images'],true);
            $url =  Env('app.api_url');
            $imagesurl = str_replace("afruit.gxfacai888.cn", $url,$good['images']);
            $imagesurls = json_encode($imagesurl,true);
            $descurl = str_replace("afruit.gxfacai888.cn", $url,$good['goodsDesc']);
            $res = (new Goods())->where('id',$good['id'])->update(['images' => $imagesurls,'goodsDesc' => $descurl]);
            dump($res);
        }
        $Sgoods = (new SystemGoods())->select();
        foreach($Sgoods as $good){
            $good['images'] = json_decode($good['images'],true);
            $url =  Env('app.api_url');
            $imagesurl = str_replace("afruit.gxfacai888.cn", $url,$good['images']);
            $imagesurls = json_encode($imagesurl,true);
            $descurl = str_replace("afruit.gxfacai888.cn", $url,$good['goodsDesc']);
            $res = (new SystemGoods())->where('id',$good['id'])->update(['images' => $imagesurls,'goodsDesc' => $descurl]);
            dump($res);
        }
        $Ogoods = (new OrderGoods())->select();
        foreach($Ogoods as $good){
            $good['images'] = json_decode($good['images'],true);
            $url =  Env('app.api_url');
            $imagesurl = str_replace("afruit.gxfacai888.cn", $url,$good['images']);
            $imagesurls = json_encode($imagesurl,true);
            $res = (new OrderGoods())->where('id',$good['id'])->update(['images' => $imagesurls]);
            dump($res);
        }
        $bgoods = (new Banner())->select();
        foreach($bgoods as $good){
            $url =  Env('app.api_url');
            $descurl = str_replace("afruit.gxfacai888.cn", $url,$good['url']);
            $res = (new Banner())->where('id',$good['id'])->update(['url' => $descurl]);
            dump($res);
        }
    }
}
